<?php
include_once "xAP-functions/webincludes.php";
echo webpageheader();



$now=date("Y-m-d H:i:s");
$id=intval($_GET["id"]);
$section=substr($_GET["section"],0,20);
$page=0;
$current=array(); // to hold the current list of channels



//get current list
$result=dbquery("select EventID from xAP_EventLink where EventSourceID=".$id);
foreach($result as $row){
	$current[]=$row["EventID"];
}

$sql="select EventID,Alias,Active 
from xAP_Event 
order by Alias";

$results=dbquery($sql);



//display
echo "
<form action='source_update.php' method='POST'>
<input type='hidden' name='page' value='$page'>
<input type='hidden' name='id' value='$id'>
<input type='hidden' name='section' value='$section'>
<table width=100%>
<TR><TD class='boldtext'></td><TD class='boldtext'>Select required events</td><td></td></tr>";


foreach($results as $row){
	echo "<tr>
	<TD class='normaltext'>";
	if (in_array($row["EventID"],$current)){
		echo "<input type='checkbox' name='event[]' value='".$row["EventID"]."' CHECKED>";
	}else{
		echo "<input type='checkbox' name='event[]' value='".$row["EventID"]."'>";
	}
	
	echo "</td>
	<TD class='normaltext' width=100%>".$row["Alias"]."</td>
	<TD class='normaltext'>
	</td>
	</tr>";
	echo "<TR bgcolor='#dddddd'><td colspan=3 height=1></td></tr>";
}

echo "<TR><td colspan=3 ><input type='submit' value='Save'></td></tr>";
echo "</table>
</form>";

echo webpagefooter();
?>